﻿using System;
using System.Globalization;

namespace NeuralStock.Entities
{
    public class CompanyQuotationData : ICsvLineParser
    {
        public DateTime? Date { get; set; }
        public decimal? Price { get; set; }

        public object ParseLine(string line)
        {
            var lineAfterSplit = line.Split(',');

            var returnData = new CompanyQuotationData();
            
            returnData.Date = DateTime.ParseExact(lineAfterSplit[1], "yyyyMMdd", CultureInfo.InvariantCulture);
            returnData.Price = Decimal.Parse(lineAfterSplit[5], CultureInfo.InvariantCulture);

            return returnData;
        }

        public bool IsValid()
        {
            if (!Date.HasValue || !Price.HasValue)
            {
                return false;
            }
            return true;
        }
    }
}
